<template>
	<navbar title="我的培训" :isBack="true"></navbar>
	<u-tabs :list="tabs" :is-scroll="false" v-model="current" @change="tabsChange" active-color="#3F4780"></u-tabs>
	<view class="page">
		<item :list="list" :type="type"></item>
		<view class="" v-if="list.length <= 0">
			<nodata></nodata>
		</view>
	</view>
</template>

<script setup lang="ts">
	import { ref, reactive } from 'vue'
	import item from './item.vue'
	import { onLoad, onShow } from '@dcloudio/uni-app'
	import { speedOrderList } from '@/service/api/speed'
	import { cityOrderList } from '@/service/api/city'
	import nodata from '@/components/nodata.vue'
	const tabs = ref([
		{
			name: '七天速成'
		},
		{
			name: "城市巡回"
		}
	])
	const param = reactive({
		page: 1,
	})
	const type = ref(1)//1是七天速成 2是城市巡回
	const list = ref([]) as any
	const current = ref(0)
	onLoad((options) => {
		if(options.type){
			type.value = options.type;
		}
		
	})
	onShow(()=>{
		if (type.value == 1) {
			getSpeedList()
		}
		if (type.value == 2) {
			getcityList()
		}
	})
	//七天速成列表
	const getSpeedList = async () => {
		const res = await speedOrderList(param);
		list.value = res.msg.data;
		console.log('七天速成');
 
	}
	//城市巡回列表
	const getcityList = async () => {

		const res = await cityOrderList(param);
		list.value = res.msg.data;
		current.value = 1;
		console.log(res);
		console.log('城市巡回');
	}
	const tabsChange = (v : any) => {
		// console.log(v);
	 		list.value =[]
		if(v == 0){
			type.value = 1
			getSpeedList()
		}else{
			type.value = 2
			getcityList()
		}
	}
</script>

<style scoped lang="scss">
	.page {
		min-height: calc(100vh - 68px);
		background-color: #F8F8F9;
		padding: 20rpx 30rpx 30rpx 20rpx;
		overflow: hidden;
	}
</style>